package com.fary.configuration;

import com.fary.vo.User;
import org.springframework.context.annotation.DeferredImportSelector;
import org.springframework.core.type.AnnotationMetadata;

import java.util.ArrayList;
import java.util.List;

public class MyDeferredImportSelector implements DeferredImportSelector {

    @Override
    public Class<? extends Group> getImportGroup() {
        return DeferredImportSelectorBeanGroup.class;
    }

    @Override
    public String[] selectImports(AnnotationMetadata importingClassMetadata) {
        return new String[]{User.class.getName()};
    }

    private static class DeferredImportSelectorBeanGroup implements DeferredImportSelector.Group {

        private final List<Entry> instanceImports = new ArrayList<>();

        @Override
        public void process(AnnotationMetadata metadata, DeferredImportSelector selector) {
            for (String importClassName : selector.selectImports(metadata)) {
                this.instanceImports.add(new Entry(metadata, importClassName));
            }
        }

        @Override
        public Iterable<Entry> selectImports() {
            return instanceImports;
        }
    }
}
